import {CHANGE_CUSTOMIZE, CHANGE_GROUP, CustomizeActionTypes} from "./action";
import {GroupField} from "../../pages/customize/group";
import {CustomizeFields} from "../../pages/customize/service";

export interface CustomizeState {
    group: GroupField;
    customize: CustomizeFields
}

const defaultState: CustomizeState = {
    group: {
        id: 0,
        title: '',
        desc: '',
        up_time: ''
    },
    customize: {
        id: 0,
        group_id: 0,
        title: '',
        status: 'waiting',
        script: '',
        desc: '',
        run_time: '',
        run_len: 0,
        base_path: '',
        linking: '',
        log_path: '',
        exec_way: '',
        log_type: 'static',
        log_read_line: 1000
    }
}

export default function customizeReducer(state = defaultState, action: CustomizeActionTypes) {
    switch (action.type) {
        case CHANGE_CUSTOMIZE:
            return {
                ...state,
                customize: {...action.payload}
            }
        case CHANGE_GROUP:
            return {
                ...state,
                group: {...action.payload}
            }
        default:
            return state
    }
}